package com.wcsy.myblog.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class fileConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //        addResourceHandler是指你想在url请求的路径
        // addResourceLocations是图片存放的真实路
        File file2  = new File("src\\main\\resources\\static\\img\\");
        String file1 = file2.getAbsolutePath();
        registry.addResourceHandler("/img/**").
                addResourceLocations("file:"+file1+"/");
//                addResourceLocations("file:G:/img/");
 }
}
